package prog.view;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import prog.Main;
import prog.model.Project;
/*
 * ProjectPropertyPanel.java
 *
 * Created on Jan 8, 2011, 5:50:32 PM
 */

/**
 *
 * @author MrKhoai
 */
public class ProjectPropertyPanel extends javax.swing.JPanel {
    private DefaultMutableTreeNode project = null;
    private DefaultMutableTreeNode fileFilter = null;
    private DefaultMutableTreeNode textEx = null;
    private DefaultMutableTreeNode imgEx = null;
    private DefaultMutableTreeNode videoEx = null;
    private DefaultMutableTreeNode audioEx = null;
    private DefaultMutableTreeNode archiveEx = null;
    private DefaultMutableTreeNode userDefinedEx = null;

    /** Creates new form ProjectPropertyPanel */
    public ProjectPropertyPanel() {
        initComponents();
        addListenner();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jPanel1.setLayout(new java.awt.GridBagLayout());
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = createTree();
        textExtensionPanel2 = new TextExtensionPanel();
        archiveExtensionPanel1 = new ArchiveExtensionPanel();
        audioExtensionPanel1 = new AudioExtensionPanel();
        imgExtensionPanel1 = new ImgExtensionPanel();
        userDefinedExtensionPanel1 = new UserDefinedExtensionPanel();
        videoExtensionPanel1 = new VideoExtensionPanel();
        projectPanel1 = new ProjectPanel();
        bt_Ok = new javax.swing.JButton();
        bt_Cancel = new javax.swing.JButton();
        bt_Apply = new javax.swing.JButton();

        jPanel1.setLayout(new java.awt.GridBagLayout());

        jTree1.setRootVisible(false);
        jScrollPane1.setViewportView(jTree1);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 181;
        gridBagConstraints.ipady = 389;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(11, 10, 49, 0);
        jPanel1.add(jScrollPane1, gridBagConstraints);

        textExtensionPanel2.setPreferredSize(new java.awt.Dimension(460, 380));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 7;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 36;
        gridBagConstraints.ipady = 40;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 18, 49, 18);
        jPanel1.add(textExtensionPanel2, gridBagConstraints);

        archiveExtensionPanel1.setPreferredSize(new java.awt.Dimension(460, 380));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 36;
        gridBagConstraints.ipady = 40;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 18, 49, 18);
        jPanel1.add(archiveExtensionPanel1, gridBagConstraints);

        audioExtensionPanel1.setPreferredSize(new java.awt.Dimension(460, 380));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 36;
        gridBagConstraints.ipady = 40;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 18, 49, 18);
        jPanel1.add(audioExtensionPanel1, gridBagConstraints);

        imgExtensionPanel1.setPreferredSize(new java.awt.Dimension(460, 380));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 36;
        gridBagConstraints.ipady = 40;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 18, 49, 18);
        jPanel1.add(imgExtensionPanel1, gridBagConstraints);

        userDefinedExtensionPanel1.setPreferredSize(new java.awt.Dimension(460, 380));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 36;
        gridBagConstraints.ipady = 40;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 18, 49, 18);
        jPanel1.add(userDefinedExtensionPanel1, gridBagConstraints);

        videoExtensionPanel1.setPreferredSize(new java.awt.Dimension(460, 380));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 36;
        gridBagConstraints.ipady = 40;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 18, 49, 18);
        jPanel1.add(videoExtensionPanel1, gridBagConstraints);

        projectPanel1.setPreferredSize(new java.awt.Dimension(460, 380));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.ipadx = 61;
        gridBagConstraints.ipady = 68;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 18, 49, 18);
        jPanel1.add(projectPanel1, gridBagConstraints);

        bt_Ok.setText("Đồng ý");
        bt_Ok.setActionCommand("Ok");

        bt_Cancel.setText("Hủy");
        bt_Cancel.setActionCommand("Cancel");

        bt_Apply.setText("Áp dụng");
        bt_Apply.setActionCommand("Apply");
        bt_Apply.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(279, 279, 279)
                .addComponent(bt_Ok)
                .addGap(18, 18, 18)
                .addComponent(bt_Cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(bt_Apply)
                .addContainerGap(3352, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 3878, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 445, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_Cancel)
                    .addComponent(bt_Apply)
                    .addComponent(bt_Ok))
                .addContainerGap(53, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    protected javax.swing.JTree createTree() {
        DefaultMutableTreeNode top = new DefaultMutableTreeNode();
        project = new DefaultMutableTreeNode("Dự án");
        top.add(project);
        fileFilter = new DefaultMutableTreeNode("Lọc file");
        top.add(fileFilter);

        textEx = new DefaultMutableTreeNode("Văn bản");
        fileFilter.add(textEx);

        imgEx = new DefaultMutableTreeNode("Hình ảnh");
        fileFilter.add(imgEx);

        videoEx = new DefaultMutableTreeNode("Video");
        fileFilter.add(videoEx);

        audioEx = new DefaultMutableTreeNode("Audio");
        fileFilter.add(audioEx);

        archiveEx = new DefaultMutableTreeNode("File nén");
        fileFilter.add(archiveEx);

        userDefinedEx = new DefaultMutableTreeNode("Tự định nghĩa");
        fileFilter.add(userDefinedEx);

        DefaultTreeModel model = new DefaultTreeModel(top);
        javax.swing.JTree tree = new JTree(model);
        tree.expandRow(2);
        tree.addTreeSelectionListener(new MyListener());
        tree.setPreferredSize(new Dimension(100,200));
        return tree;
    }

    protected void setViewPanel() {
        archiveExtensionPanel1.setVisible(false);
        audioExtensionPanel1.setVisible(false);
        imgExtensionPanel1.setVisible(false);
        textExtensionPanel2.setVisible(false);
        userDefinedExtensionPanel1.setVisible(false);
        videoExtensionPanel1.setVisible(false);
        projectPanel1.setVisible(false);
    }

    public void setViewPanelDefault(String defaultView) {
        jTree1.clearSelection();
        if(defaultView.equals("TEXT")) {
            jTree1.addSelectionRow(2);
        }
        if(defaultView.equals("IMG")) {
            jTree1.addSelectionRow(3);
        }
        if(defaultView.equals("VIDEO")) {
            jTree1.addSelectionRow(4);
        }
        if(defaultView.equals("AUDIO")) {
            jTree1.addSelectionRow(5);
        }
        if(defaultView.equals("ARCHIVE")) {
            jTree1.addSelectionRow(6);
        }
        if(defaultView.equals("USERDEFINED")) {
            jTree1.addSelectionRow(7);
        }
        if(defaultView.equals("PROJECT")) {
            jTree1.addSelectionRow(0);
        }
    }

    public void addListenner() {
        MyListener listenner = new MyListener();
        bt_Ok.addActionListener(listenner);
        bt_Cancel.addActionListener(listenner);
        bt_Apply.addActionListener(listenner);
    }

    public void clickBt_Ok() {
        Project pj = projectPanel1.getProject();
        Main.program.mainForm.pnWorkArea.addProject(pj);
        Main.program.projectPropertyForm.showForm(false);
        projectPanel1.clear();
    }

    public void clickBt_Cancel() {
        Main.program.projectPropertyForm.showForm(false);
        projectPanel1.clear();
    }

    public void load() {
        projectPanel1.load();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private ArchiveExtensionPanel archiveExtensionPanel1;
    private AudioExtensionPanel audioExtensionPanel1;
    private javax.swing.JButton bt_Apply;
    private javax.swing.JButton bt_Cancel;
    private javax.swing.JButton bt_Ok;
    private ImgExtensionPanel imgExtensionPanel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTree jTree1;
    private ProjectPanel projectPanel1;
    private TextExtensionPanel textExtensionPanel2;
    private UserDefinedExtensionPanel userDefinedExtensionPanel1;
    private VideoExtensionPanel videoExtensionPanel1;
    // End of variables declaration//GEN-END:variables

    class MyListener implements TreeSelectionListener, ActionListener {

        public void valueChanged(TreeSelectionEvent e) {
            TreePath path = e.getPath();
            DefaultMutableTreeNode choose = (DefaultMutableTreeNode)path.getPath()[path.getPath().length - 1];

            if(choose.equals(fileFilter)) {
                System.out.println("file filter");
            }
            if(choose.equals(textEx)) {
                setViewPanel();
                textExtensionPanel2.setVisible(true);
            }
            if(choose.equals(imgEx)) {
                setViewPanel();
                imgExtensionPanel1.setVisible(true);
            }
            if(choose.equals(videoEx)) {
                setViewPanel();
                videoExtensionPanel1.setVisible(true);
            }
            if(choose.equals(audioEx)) {
                setViewPanel();
                audioExtensionPanel1.setVisible(true);
            }
            if(choose.equals(archiveEx)) {
                setViewPanel();
                archiveExtensionPanel1.setVisible(true);
            }
            if(choose.equals(userDefinedEx)) {
                setViewPanel();
                userDefinedExtensionPanel1.setVisible(true);
            }
            if(choose.equals(project)) {
                setViewPanel();
                projectPanel1.setVisible(true);
            }
        }

        public void actionPerformed(ActionEvent e) {
            String actionCommand = e.getActionCommand();
            if(actionCommand.equals("Ok")) {
                clickBt_Ok();
            }
            if(actionCommand.equals("Cancel")) {
                clickBt_Cancel();
            }
            if(actionCommand.equals("Apply")) {

            }
        }

    }
}